package queue

import "errors"

type ArrQueue struct {
	size     int
	capacity int
	Data     []any
}

func NewArrQueue(capacity int) *ArrQueue {
	return &ArrQueue{
		size:     0,
		capacity: capacity,
		Data:     make([]any, 0, capacity),
	}
}

func (a *ArrQueue) Size() int {
	return a.size
}

func (a *ArrQueue) Capacity() int {
	return a.capacity
}

func (a *ArrQueue) Push(val any) error {
	if a.size == a.capacity {
		return errors.New("failure: capacity is full")
	}

	a.Data = append(a.Data, val)
	a.size++
	return nil
}

func (a *ArrQueue) Pop() any {
	if a.size <= 0 {
		return nil
	}

	val := (a.Data)[0]
	var newArr []any
	if a.size == 1 {
		a.Data = newArr
		a.size--
		return val
	}

	if a.size > 1 {
		// a.Data = (a.Data)[1:]
		var newArr []any
		for i := 1; i < a.size; i++ {
			newArr = append(newArr, a.Data[i])
		}

		a.Data = newArr
	}

	a.size--
	return val
}
